package egs;

                         // can be abstract class-
/*class Super1{   // if we make class cinal then it cannot be subclassed
	int x;                 
	Super1(int x){
		this.x=x;
		}
	final int add(){
		return x+x;
		
	}
	public void disp(){                             // if add final keyword to this method then...
		System.out.println("sup x="+ x);     // can make disp() abstract- abstract-overriding compulsory.
	}
}

class sub1 extends Super1{
	int y;
	sub1(int x,int y){
		super(x);
		this.y=y;
		}
	public void disp(){                   // cannot override that super class method in the sub class.
		System.out.println("sup x="+x);
		System.out.println("y="+y);
	}
}
public class override {
	public static void main(String[] args) {
		
		Super1 a=new sub1(10,20);  Dynamic method dispatch is the mechanism by which a call to an overridden method is resolved at run time, 
		                               rather than compile time.
                                 Dynamic method dispatch is important because this is how Java implements run-time polymorphism.
		a.disp();
	
	sub1 s1=new sub1(1,2);
	s1.disp();
	sub1 s2=new sub1(10,20);
	int s=s2.add();
	System.out.println(s);
	
	
	}

}

*/


/*class Super1{
	  public void method(){
		  System.out.println("super");
	  }
}
class sub1 extends Super1{
	public void method(){
		 System.out.println("sub");
	}
}
public class override{
	public static void main(String[] args){
		  Super1 a=new sub1();
		  a.method();
	}
}*/


// Applying Acces modifiers with method overriding
// if u are overriding any method ,overridden method (in subclass )
//  must not be more restrictive.

/*
 class B{
	protected void msg() { System.out.println(" in B !! "); }
	}
public class override extends B{
	void msg() { System.out.println(" in override class !"); } // compiler error- default modifier is more restrictive
public static void main(String[] args){
	override obj=new override();
obj.msg();
}
}

*/
class B{
	 void msg1() { System.out.println(" in B !! "); }
	}
public class override extends B{
	protected void msg1() { System.out.println(" in override class !"); } // No.. compiler error
public static void main(String[] args){
	override obj=new override();
obj.msg1();
}
}

